<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    //编写一个函数来查找字符串数组中的最长公共前缀。
    //如果不存在公共前缀，返回空字符串 ""。
    // 示例 1：
    //输入：strs = ["flower", "flow", "flight"]
    //输出："fl"
    // 示例 2：

    //输入：strs = ["dog", "racecar", "car"]
    //输出：""
    //解释：输入不存在公共前缀。

    function longestCommonPrefix(strs) {
        let re = strs[0] || "";
        if (strs.length == 1) {
            return strs[0]
        }
        for (let i = 0; i < strs.length; i++) {
            while (strs[i].slice(0, re.length) !== re) {
                re = re.slice(0, re.length - 1)
            }
        }
        return re
    };

    console.log(longestCommonPrefix(["flower", "flow", "flight"]));
    console.log(longestCommonPrefix(["dog", "racecar", "car"]));
</script>